package com.shanghaionstar.mro.util;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by kai zhang on 2015/10/14.
 */
public class MrOJsonUtil {
    public static String getOperationType(String json) {
        String operationType = "";
        try {
            JSONObject obj = new JSONObject(json);
            operationType = obj.getString("operationType");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return operationType;
    }

    public static String getContent(String json) {
        String content = "";
        try {
            JSONObject obj = new JSONObject(json);
            JSONObject data = obj.getJSONObject("data");
            content = data.getString("content");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return content;
    }

    public static String getAnswer(String json) {
        String content = "";
        try {
            JSONObject obj = new JSONObject(json);
            JSONObject data = obj.getJSONObject("data");
            content = data.getString("answer");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return content;
    }

    public static String getValue(String json) {
        String content = "";
        try {
            JSONObject obj = new JSONObject(json);
            JSONObject data = obj.getJSONObject("data");
            content = data.getString("value");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return content;
    }

    public static String getPOIName(String json) {
        String content = "";
        try {
            JSONObject obj = new JSONObject(json);
            JSONObject data = obj.getJSONObject("data");
            content = data.getString("POIName");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return content;
    }

    public static boolean isStatusSuccess(String json) {
        String status = "";
        try {
            JSONObject obj = new JSONObject(json);
            status = obj.getString("status");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return "success".equals(status);
    }

    public static String getStatus(String json) {
        String status = "";
        try {
            JSONObject obj = new JSONObject(json);
            status = obj.getString("status");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return status;
    }
}
